Page({
  onShowToast() {
    wx.showToast({
      title: '购买成功',
      icon: 'loading',   // error
      duration: 3000,
      mask: true,
      success: res => {
        console.log(res, 'res')
      },
      fail: error => {
        console.log(error, 'error')
      }
    })

    /* wx.showLoading({
      title: '加载中',
    }) */
  },
  onShowModel() {
    wx.showModal({
      title: '确定购买吗?',
      content: "确定购买的话, 请确定你的账户是否有钱",
      confirmColor: '#f00',
      cancelColor: '0f0f00',
      success: res => {
        if(res.confirm) {
          console.log('用户点击了确定')
        } else {
          console.log('用户点击了取消')
        }
      }
    })
  },
  onShowActionSheet() {
    wx.showActionSheet({
      itemList: ['衣服', '裤子', '鞋子'],
      success: res => {
        console.log(res, 'showActionSheet')
      },
      fail: error => {
        console.log(error, 'error')
      }
    })
  },

  // 2. 分享功能
  onShareAppMessage() {
    return {
      title: '路途的内容',
      path: "/pages/favor/index",
      imageUrl: '/assets/nhlt.jpg'
    }
  },

  // 3. 获取设备信息
  onGetSystemInfo() {
    // 1. 获取手机的基本信息
    /* wx.getSystemInfo({
      success: (result) => {
        console.log(result, 'result')
      },
    }) */

    // 2. 获取手机的位置信息
    wx.getLocation({
      success: res => {
        console.log(res, 'getLocation')
      }
    })
  },

  // 4. 本地存储方式
  onLocalStorage() {
    wx.setStorageSync('name', 'why')
    wx.setStorageSync('age', 18)
    wx.setStorageSync('friends', ['abc', 'cba', 'nba'])

    const name = wx.getStorageSync('name')
    const age = wx.getStorageSync('age')
    const friends = wx.getStorageSync('friends')

    console.log(name, age, friends)

    wx.removeStorageSync('name')

    wx.clearStorageSync()

    wx.setStorage({
      key: 'books',
      data: ['abc', 'cba', 'nab'],
      encrypt: true,    // 是否加密, 只对异步的存储有效, 获取时解密也需要使用encrypt: true
      success: res => {
        console.log(res)
      }
    })
  }
})